from flask_login import UserMixin
from sqlalchemy import func

from exts import db, get_time


# orm模型
class User(db.Model, UserMixin):
    __tablename__ = "user"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(45), nullable=False, unique=True)
    password = db.Column(db.String(45), nullable=False)
    name = db.Column(db.String(45), nullable=False)
    power = db.Column(db.Integer, nullable=False)


class Capture(db.Model):
    __tablename__ = "capture"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    person_id = db.Column(db.String(45), nullable=False)
    person_label = db.Column(db.String(45), nullable=False)

    create_time = db.Column(db.DateTime, server_default=func.now())
    update_time = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())
    is_delete = db.Column(db.Integer, server_default='0')


class PassersBy(db.Model):
    __tablename__ = "passers_by"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    up_or_down = db.Column(db.String(45), nullable=False)
    count = db.Column(db.String(45), nullable=False)
    person_id = db.Column(db.String(45), nullable=False)
    person_label = db.Column(db.String(45), nullable=False)

    create_time = db.Column(db.DateTime, server_default=func.now())
    update_time = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())
    is_delete = db.Column(db.Integer, server_default='0')


class PictureCut(db.Model):
    __tablename__ = "picture_cut"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    path = db.Column(db.String(200), nullable=False)

    create_time = db.Column(db.DateTime, server_default=func.now())
    update_time = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())
    is_delete = db.Column(db.Integer, server_default='0')


class Group(db.Model):
    __tablename__ = "group"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    mask = db.Column(db.Integer, nullable=False)
    no_mask = db.Column(db.Integer, nullable=False)

    create_time = db.Column(db.DateTime, server_default=func.now())
    update_time = db.Column(db.DateTime, server_default=func.now(), onupdate=func.now())
    is_delete = db.Column(db.Integer, server_default='0')
